/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Result.java
 *
 * Created on 19-feb-2013, 1:04:00
 */
package sisvoto.vista;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JTextField;
import net.sf.jasperreports.engine.JRException;
import sisvoto.DAO.ConsultasBD;
import sisvoto.Reportes.Reportes;
import sisvoto.Utiles.Mensajes;
import sisvoto.Utiles.MetodoConteo;
import sisvoto.modelo.Eleccion;
import sisvoto.modelo.EleccionActual;
import sisvoto.modelo.ListaVoto;
import sisvoto.modelo.PartidoElectoral;
import sisvoto.modeloTablas.ModelTablelistavoto;

/**
 *
 * @author Dianita
 */
public class Result extends javax.swing.JFrame {

    Eleccion eleccion = null;

    /** Creates new form Result */
    public Result(Eleccion eleccion) {
        this.eleccion = eleccion;
        initComponents();
         inicio();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imagePanel1 = new com.mycsistemas.swingec.panel.ImagePanel();
        curvesPanel1 = new com.mycsistemas.swingec.panel.CurvesPanel();
        jLblCandidatos1 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLblCrtBus1 = new javax.swing.JLabel();
        txtvotosblancos = new javax.swing.JTextField();
        btnvotosblancos = new javax.swing.JButton();
        jLblCrtBus6 = new javax.swing.JLabel();
        txtvotosnulos = new javax.swing.JTextField();
        btnvotosnulos = new javax.swing.JButton();
        btnvotosvalidos = new javax.swing.JButton();
        txtvotosvalidos = new javax.swing.JTextField();
        jLblCrtBus7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblresultados = new javax.swing.JTable();
        jLblCrtBus10 = new javax.swing.JLabel();
        txtganador = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLblCrtBus3 = new javax.swing.JLabel();
        jLblCrtBus4 = new javax.swing.JLabel();
        jLblCrtBus5 = new javax.swing.JLabel();
        txtelectoressi = new javax.swing.JTextField();
        txtelectoresno = new javax.swing.JTextField();
        txttotalelectores = new javax.swing.JTextField();
        btntotalelectores = new javax.swing.JButton();
        btnelectoresno = new javax.swing.JButton();
        btnelectoressiop = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLblCrtBus2 = new javax.swing.JLabel();
        txtlistas = new javax.swing.JTextField();
        btnlistas = new javax.swing.JButton();
        btnsalir = new javax.swing.JButton();
        jcbmetodo = new javax.swing.JComboBox();
        jLblCrtBus8 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLblCrtBus9 = new javax.swing.JLabel();
        btnconteo = new javax.swing.JButton();
        btnbuscar = new javax.swing.JButton();
        btnImpresultados = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Resultados de Elección");

        imagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/''_10102012_1738.jpeg"))); // NOI18N

        curvesPanel1.setLayout(null);

        jLblCandidatos1.setFont(new java.awt.Font("Georgia", 3, 18));
        jLblCandidatos1.setForeground(new java.awt.Color(255, 255, 255));
        jLblCandidatos1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLblCandidatos1.setText("Resultados Electorales");
        curvesPanel1.add(jLblCandidatos1);
        jLblCandidatos1.setBounds(140, 30, 310, 30);

        txtBuscar.setEditable(false);
        curvesPanel1.add(txtBuscar);
        txtBuscar.setBounds(40, 90, 340, 40);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resultados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 10), java.awt.Color.white)); // NOI18N
        jPanel1.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.setOpaque(false);
        jPanel1.setLayout(null);

        jLblCrtBus1.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus1.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus1.setText("Ganador:");
        jPanel1.add(jLblCrtBus1);
        jLblCrtBus1.setBounds(40, 290, 210, 30);

        txtvotosblancos.setEditable(false);
        txtvotosblancos.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel1.add(txtvotosblancos);
        txtvotosblancos.setBounds(190, 20, 190, 30);

        btnvotosblancos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/document_32.png"))); // NOI18N
        btnvotosblancos.setText("Ver");
        btnvotosblancos.setEnabled(false);
        btnvotosblancos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnvotosblancosActionPerformed(evt);
            }
        });
        jPanel1.add(btnvotosblancos);
        btnvotosblancos.setBounds(390, 20, 90, 30);

        jLblCrtBus6.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus6.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus6.setText("Nro. de Votos Blancos:");
        jPanel1.add(jLblCrtBus6);
        jLblCrtBus6.setBounds(20, 20, 210, 30);

        txtvotosnulos.setEditable(false);
        txtvotosnulos.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel1.add(txtvotosnulos);
        txtvotosnulos.setBounds(190, 60, 190, 30);

        btnvotosnulos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/warning_32.png"))); // NOI18N
        btnvotosnulos.setText("Ver");
        btnvotosnulos.setEnabled(false);
        btnvotosnulos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnvotosnulosActionPerformed(evt);
            }
        });
        jPanel1.add(btnvotosnulos);
        btnvotosnulos.setBounds(390, 60, 90, 30);

        btnvotosvalidos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/visto.png"))); // NOI18N
        btnvotosvalidos.setText("Ver");
        btnvotosvalidos.setEnabled(false);
        btnvotosvalidos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnvotosvalidosActionPerformed(evt);
            }
        });
        jPanel1.add(btnvotosvalidos);
        btnvotosvalidos.setBounds(390, 100, 90, 30);

        txtvotosvalidos.setEditable(false);
        txtvotosvalidos.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel1.add(txtvotosvalidos);
        txtvotosvalidos.setBounds(190, 100, 190, 30);

        jLblCrtBus7.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus7.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus7.setText("Nro. de Votos Nulos:");
        jPanel1.add(jLblCrtBus7);
        jLblCrtBus7.setBounds(20, 60, 210, 30);

        tblresultados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblresultados.setEnabled(false);
        jScrollPane1.setViewportView(tblresultados);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(20, 140, 460, 130);

        jLblCrtBus10.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus10.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus10.setText("Nro. de Votos:");
        jPanel1.add(jLblCrtBus10);
        jLblCrtBus10.setBounds(20, 100, 210, 30);

        txtganador.setEditable(false);
        jPanel1.add(txtganador);
        txtganador.setBounds(130, 290, 350, 30);

        curvesPanel1.add(jPanel1);
        jPanel1.setBounds(550, 90, 500, 340);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Electores", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 10), java.awt.Color.white)); // NOI18N
        jPanel2.setForeground(new java.awt.Color(255, 255, 255));
        jPanel2.setOpaque(false);
        jPanel2.setLayout(null);

        jLblCrtBus3.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus3.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus3.setText("Nro. Total de Electores:");
        jPanel2.add(jLblCrtBus3);
        jLblCrtBus3.setBounds(20, 30, 190, 30);

        jLblCrtBus4.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus4.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus4.setText("Electores Que No Sufragaron:");
        jPanel2.add(jLblCrtBus4);
        jLblCrtBus4.setBounds(20, 70, 220, 30);

        jLblCrtBus5.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus5.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus5.setText("Electores Que Si Sufragaron:");
        jPanel2.add(jLblCrtBus5);
        jLblCrtBus5.setBounds(20, 110, 220, 30);

        txtelectoressi.setEditable(false);
        txtelectoressi.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel2.add(txtelectoressi);
        txtelectoressi.setBounds(240, 110, 130, 30);

        txtelectoresno.setEditable(false);
        txtelectoresno.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel2.add(txtelectoresno);
        txtelectoresno.setBounds(240, 70, 130, 30);

        txttotalelectores.setEditable(false);
        txttotalelectores.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel2.add(txttotalelectores);
        txttotalelectores.setBounds(240, 30, 130, 30);

        btntotalelectores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/User1.png"))); // NOI18N
        btntotalelectores.setText("Ver");
        btntotalelectores.setEnabled(false);
        btntotalelectores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btntotalelectoresActionPerformed(evt);
            }
        });
        jPanel2.add(btntotalelectores);
        btntotalelectores.setBounds(390, 30, 90, 30);

        btnelectoresno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/User1.png"))); // NOI18N
        btnelectoresno.setText("Ver");
        btnelectoresno.setEnabled(false);
        btnelectoresno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnelectoresnoActionPerformed(evt);
            }
        });
        jPanel2.add(btnelectoresno);
        btnelectoresno.setBounds(390, 70, 90, 30);

        btnelectoressiop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/User1.png"))); // NOI18N
        btnelectoressiop.setText("Ver");
        btnelectoressiop.setEnabled(false);
        btnelectoressiop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnelectoressiopActionPerformed(evt);
            }
        });
        jPanel2.add(btnelectoressiop);
        btnelectoressiop.setBounds(390, 110, 90, 30);

        curvesPanel1.add(jPanel2);
        jPanel2.setBounds(30, 150, 500, 170);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Partidos Electorales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 10), java.awt.Color.white)); // NOI18N
        jPanel3.setForeground(new java.awt.Color(255, 255, 255));
        jPanel3.setOpaque(false);
        jPanel3.setLayout(null);

        jLblCrtBus2.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus2.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus2.setText("Nro. Total Listas Inscritas:");
        jPanel3.add(jLblCrtBus2);
        jLblCrtBus2.setBounds(20, 30, 210, 30);

        txtlistas.setEditable(false);
        txtlistas.setFont(new java.awt.Font("Arial Black", 0, 18));
        jPanel3.add(txtlistas);
        txtlistas.setBounds(240, 30, 130, 30);

        btnlistas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/clipboard_32.png"))); // NOI18N
        btnlistas.setText("Ver");
        btnlistas.setEnabled(false);
        btnlistas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlistasActionPerformed(evt);
            }
        });
        jPanel3.add(btnlistas);
        btnlistas.setBounds(390, 30, 90, 30);

        curvesPanel1.add(jPanel3);
        jPanel3.setBounds(30, 340, 500, 90);

        btnsalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/DeleteRed.png"))); // NOI18N
        btnsalir.setText("Salir");
        btnsalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsalirActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnsalir);
        btnsalir.setBounds(840, 450, 150, 40);

        jcbmetodo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Condorcet", "VUT" }));
        jcbmetodo.setEnabled(false);
        curvesPanel1.add(jcbmetodo);
        jcbmetodo.setBounds(670, 40, 230, 40);

        jLblCrtBus8.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus8.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus8.setText("Conteo de Votos:");
        curvesPanel1.add(jLblCrtBus8);
        jLblCrtBus8.setBounds(550, 60, 120, 20);

        jLabel2.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Elija la Elección que Desee Obtener los Resultados");
        curvesPanel1.add(jLabel2);
        jLabel2.setBounds(90, 130, 290, 20);

        jLblCrtBus9.setFont(new java.awt.Font("Elephant", 0, 14));
        jLblCrtBus9.setForeground(new java.awt.Color(255, 255, 255));
        jLblCrtBus9.setText("Método de ");
        curvesPanel1.add(jLblCrtBus9);
        jLblCrtBus9.setBounds(570, 40, 90, 20);

        btnconteo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/right_32.png"))); // NOI18N
        btnconteo.setText("Iniciar Conteo");
        btnconteo.setEnabled(false);
        btnconteo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnconteoActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnconteo);
        btnconteo.setBounds(910, 40, 140, 40);

        btnbuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/search_32.png"))); // NOI18N
        btnbuscar.setText("Buscar");
        btnbuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnbuscarActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnbuscar);
        btnbuscar.setBounds(390, 90, 140, 40);

        btnImpresultados.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisvoto/Recursos/print_32.png"))); // NOI18N
        btnImpresultados.setText("Imprimir Resultados");
        btnImpresultados.setEnabled(false);
        btnImpresultados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImpresultadosActionPerformed(evt);
            }
        });
        curvesPanel1.add(btnImpresultados);
        btnImpresultados.setBounds(640, 450, 190, 40);

        javax.swing.GroupLayout imagePanel1Layout = new javax.swing.GroupLayout(imagePanel1);
        imagePanel1.setLayout(imagePanel1Layout);
        imagePanel1Layout.setHorizontalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(imagePanel1Layout.createSequentialGroup()
                .addComponent(curvesPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1089, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        imagePanel1Layout.setVerticalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(curvesPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(imagePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnvotosblancosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnvotosblancosActionPerformed
// TODO add your handling code here:
    ResultadosTablas r = new ResultadosTablas(null, true, eleccion, "VOTO BLANCO");
    r.setLocationRelativeTo(this);
    r.setVisible(true);
}//GEN-LAST:event_btnvotosblancosActionPerformed

private void btnvotosnulosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnvotosnulosActionPerformed
// TODO add your handling code here:
    ResultadosTablas r = new ResultadosTablas(null, true, eleccion, "VOTO NULO");
    r.setLocationRelativeTo(this);
    r.setVisible(true);
}//GEN-LAST:event_btnvotosnulosActionPerformed

private void btnvotosvalidosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnvotosvalidosActionPerformed
// TODO add your handling code here:
    ResultadosTablas r = new ResultadosTablas(null, true, eleccion, "VOTO VALIDO");
    r.setLocationRelativeTo(this);
    r.setVisible(true);
}//GEN-LAST:event_btnvotosvalidosActionPerformed

private void btntotalelectoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntotalelectoresActionPerformed
// TODO add your handling code here:
    AdministrarElecciones ae = new AdministrarElecciones(null, true, eleccion);
    ae.setLocationRelativeTo(this);
    ae.getjTabbedPane1().setSelectedIndex(1);
    ae.setVisible(true);
}//GEN-LAST:event_btntotalelectoresActionPerformed

private void btnelectoresnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnelectoresnoActionPerformed
// TODO add your handling code here:
    ResultadosTablas r = new ResultadosTablas(null, true, eleccion, "ELECTORESNO");
    r.setLocationRelativeTo(this);
    r.setVisible(true);
}//GEN-LAST:event_btnelectoresnoActionPerformed

private void btnelectoressiopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnelectoressiopActionPerformed
// TODO add your handling code here:
    ResultadosTablas r = new ResultadosTablas(null, true, eleccion, "ELECTORESSI");
    r.setLocationRelativeTo(this);
    r.setVisible(true);
}//GEN-LAST:event_btnelectoressiopActionPerformed

private void btnsalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsalirActionPerformed
// TODO add your handling code here:
    this.dispose();
}//GEN-LAST:event_btnsalirActionPerformed

private void btnconteoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnconteoActionPerformed
// TODO add your handling code here:


    if (eleccion.getId() != null) {
        if (jcbmetodo.getSelectedItem().toString().equals("Condorcet")) {
            ArrayList<ListaVoto> res = new MetodoConteo(this).metodoCondorcet(eleccion);

            for (ListaVoto r : res) {
                if (!r.getIdpartido().equals("NULO") && !r.getIdpartido().equals("BLANCO")) {
                    PartidoElectoral p = ((ArrayList<PartidoElectoral>) new ConsultasBD().buscarPOR("PartidoElectoral", "id", "'" + r.getIdpartido() + "'")).get(0);
                    r.setIdpartido(p.getNombre());
                } else {
                    r.setIdpartido("TOTAL DE VOTOS " + r.getIdpartido() + "S");
                }
            }
            ListaVoto aux = res.get(0);
            if (!aux.getIdpartido().equals("TOTAL DE VOTOS NULOS") && !aux.getIdpartido().equals("TOTAL DE VOTOS BLANCOS")) {
                if (res.size() >= 2) {
                    if (res.get(0).getVotos() > res.get(1).getVotos()) {
                        txtganador.setText(aux.getIdpartido());
                    } else {
                        txtganador.setText("EMPATE TÉCNICO");
                    }
                } else {
                    txtganador.setText(aux.getIdpartido());
                }

            } else {
                txtganador.setText(res.get(0).getIdpartido() + " NO SE PUEDE DETERMINAR UN GANADOR");
            }
            ModelTablelistavoto modelo = new ModelTablelistavoto(res);
            tblresultados.setModel(modelo);
            tblresultados.updateUI();
            activarbotones();
        }
    }
}//GEN-LAST:event_btnconteoActionPerformed

private void btnbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbuscarActionPerformed
// TODO add your handling code here:

    BuscarElecciones be = new BuscarElecciones(this, true, this);
    be.setLocationRelativeTo(this);
    be.setVisible(true);



}//GEN-LAST:event_btnbuscarActionPerformed

   public JTextField getTxtelectoresno() {
        return txtelectoresno;
    }

    public void setTxtelectoresno(JTextField txtelectoresno) {
        this.txtelectoresno = txtelectoresno;
    }

    public JTextField getTxtelectoressi() {
        return txtelectoressi;
    }

    public void setTxtelectoressi(JTextField txtelectoressi) {
        this.txtelectoressi = txtelectoressi;
    }

    public JTextField getTxtlistas() {
        return txtlistas;
    }

    public void setTxtlistas(JTextField txtlistas) {
        this.txtlistas = txtlistas;
    }

    public JTextField getTxttotalelectores() {
        return txttotalelectores;
    }

    public void setTxttotalelectores(JTextField txttotalelectores) {
        this.txttotalelectores = txttotalelectores;
    }

    public JTextField getTxtvotosblancos() {
        return txtvotosblancos;
    }

    public void setTxtvotosblancos(JTextField txtvotosblancos) {
        this.txtvotosblancos = txtvotosblancos;
    }

    public JTextField getTxtvotosnulos() {
        return txtvotosnulos;
    }

    public void setTxtvotosnulos(JTextField txtvotosnulos) {
        this.txtvotosnulos = txtvotosnulos;
    }

    public JTextField getTxtvotosvalidos() {
        return txtvotosvalidos;
    }

    public void setTxtvotosvalidos(JTextField txtvotosvalidos) {
        this.txtvotosvalidos = txtvotosvalidos;
    }
private void btnlistasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlistasActionPerformed
// TODO add your handling code here:
    AdministrarElecciones ae = new AdministrarElecciones(null, true, eleccion);
    ae.setLocationRelativeTo(this);
    ae.getjTabbedPane1().setSelectedIndex(2);
    ae.setVisible(true);
    
}//GEN-LAST:event_btnlistasActionPerformed

private void btnImpresultadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImpresultadosActionPerformed
// TODO add your handling code here:}
        if (!txtganador.getText().isEmpty()) {
        HashMap mapa = new HashMap();
        mapa.put("tituloeleccion", txtBuscar.getText());
        mapa.put("ganador", txtganador.getText());
        mapa.put("totale", txttotalelectores.getText());
        mapa.put("electorsi", txtelectoressi.getText());
        mapa.put("electorno", txtelectoresno.getText());
        mapa.put("votov", txtvotosvalidos.getText());
        mapa.put("votob", txtvotosblancos.getText());
        mapa.put("voton", txtvotosnulos.getText());
        String consulta = "SELECT DISTINCT(COUNT(vot.voto)) AS votos, par.nombre AS lista " +
                " FROM VotoElectoral As vot " +
                " LEFT JOIN partidoelectoral AS par ON par.id = vot.voto " +
                "WHERE vot.eleccion_id = '"+eleccion.getId()+"' AND vot.voto<>'NULO' AND vot.voto<>'BLANCO' " +
                "GROUP BY voto ORDER BY COUNT(vot.voto) DESC ";
        try {
            try {
                          
                new Reportes().reporteparametros("resultados", consulta, mapa);

            } catch (JRException ex) {
                System.out.println(ex);
            }
        } catch (SQLException ex) {
            System.out.println(ex);
        }

    }
}//GEN-LAST:event_btnImpresultadosActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnImpresultados;
    private javax.swing.JButton btnbuscar;
    private javax.swing.JButton btnconteo;
    private javax.swing.JButton btnelectoresno;
    private javax.swing.JButton btnelectoressiop;
    private javax.swing.JButton btnlistas;
    private javax.swing.JButton btnsalir;
    private javax.swing.JButton btntotalelectores;
    private javax.swing.JButton btnvotosblancos;
    private javax.swing.JButton btnvotosnulos;
    private javax.swing.JButton btnvotosvalidos;
    private com.mycsistemas.swingec.panel.CurvesPanel curvesPanel1;
    private com.mycsistemas.swingec.panel.ImagePanel imagePanel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLblCandidatos1;
    private javax.swing.JLabel jLblCrtBus1;
    private javax.swing.JLabel jLblCrtBus10;
    private javax.swing.JLabel jLblCrtBus2;
    private javax.swing.JLabel jLblCrtBus3;
    private javax.swing.JLabel jLblCrtBus4;
    private javax.swing.JLabel jLblCrtBus5;
    private javax.swing.JLabel jLblCrtBus6;
    private javax.swing.JLabel jLblCrtBus7;
    private javax.swing.JLabel jLblCrtBus8;
    private javax.swing.JLabel jLblCrtBus9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jcbmetodo;
    private javax.swing.JTable tblresultados;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtelectoresno;
    private javax.swing.JTextField txtelectoressi;
    private javax.swing.JTextField txtganador;
    private javax.swing.JTextField txtlistas;
    private javax.swing.JTextField txttotalelectores;
    private javax.swing.JTextField txtvotosblancos;
    private javax.swing.JTextField txtvotosnulos;
    private javax.swing.JTextField txtvotosvalidos;
    // End of variables declaration//GEN-END:variables
private void actvarmetodos() {
        btnconteo.setEnabled(true);
        jcbmetodo.setEnabled(true);
    }

    private void desactvarmetodos() {
        btnconteo.setEnabled(false);
        jcbmetodo.setEnabled(false);
    }

    private void activarbotones() {

        btnImpresultados.setEnabled(true);
        btnelectoresno.setEnabled(true);
        btnelectoressiop.setEnabled(true);
        btnlistas.setEnabled(true);
        btntotalelectores.setEnabled(true);
        btnvotosblancos.setEnabled(true);
        btnvotosnulos.setEnabled(true);
        btnvotosvalidos.setEnabled(true);
    }

    private void desactivarbotones() {

        btnImpresultados.setEnabled(false);
        btnelectoresno.setEnabled(false);
        btnelectoressiop.setEnabled(false);
        btnlistas.setEnabled(false);
        btntotalelectores.setEnabled(false);
        btnvotosblancos.setEnabled(false);
        btnvotosnulos.setEnabled(false);
        btnvotosvalidos.setEnabled(false);
    }

    private void limpiarelectores() {
        txttotalelectores.setText("");
        txtelectoresno.setText("");
        txtelectoressi.setText("");
    }

    private void cargarelectores(int total, int no, int si) {
        txttotalelectores.setText(String.valueOf(total));
        txtelectoresno.setText(String.valueOf(no));
        txtelectoressi.setText(String.valueOf(si));
    }

    private void limpiarlista() {
        txtlistas.setText("");
    }

    private void cargarlista(int listas) {
        txtlistas.setText(String.valueOf(listas));
    }

    private void limpiarvotos() {
        txtvotosblancos.setText("");
        txtvotosnulos.setText("");
        txtvotosvalidos.setText("");
    }

    private void inicio() {
        if (eleccion == null) {
            return;
        }
        ArrayList<EleccionActual> eleccionactual = (ArrayList<EleccionActual>) new ConsultasBD().buscarPOR("EleccionActual", "eleccion", "'" + eleccion.getId() + "'");
        if (!eleccionactual.isEmpty()) {
            EleccionActual eleccionact = eleccionactual.get(0);
            if (eleccionact.getEstado().equals("FINALIZADO")) {
                eleccion = eleccionact.getEleccion();
                txtBuscar.setText(eleccion.getTitulo());
                actvarmetodos();
            } else {
                desactivarbotones();
                desactvarmetodos();
                limpiarelectores();
                limpiarlista();
                limpiarvotos();
                new Mensajes().StandarWarning(this, "NO SE PUEDEN OBTENER LOS RESULTADOS. \n Ésta Elección aún Está Vigente");
            }
        } else {
            desactivarbotones();
            desactvarmetodos();
            limpiarelectores();
            limpiarlista();
            limpiarvotos();
            new Mensajes().StandarWarning(this, "Ésta Elección aún no ha Iniciado");
        }
    }
}
